﻿(function($) {
    widgets[1] =
        {
            widgetTypeId: 1,
            optionText: 'Toggle Button',
            valueChanged: function(notification) {
                $("#" + notification.WidgetGuid.replace(/-/g, '')).attr('checked', notification.Value.toLowerCase() == "true" ? true : false);
            },
            getHtml: function(widget) {
                return "<span class='toggle'><input type='checkbox' id='"
                    + widget.WidgetGuid.replace(/-/g, '')
                    + "' value='"
                    + (widget.CurrentValue == 0 ? "false" : "true")
                    + "'/></span>";
            },
            widgetReady: function(widget) {
                $('#' + widget.WidgetGuid.replace(/-/g, '')).bind('change', function() {
                    $.ajax({
                        type: "GET",
                        url: "/s/changeValue",
                        data: { widgetGuid: $(this).attr('id'), newValue: $(this).attr('checked') },
                        success: function(data) {
                            if (!data) {
                                $("#errorMessage").text("Error seting value!");
                                $('#errorPane').makeFloaty({
                                    spacing: 20, time: '1s'
                                });
                            }
                        }
                    });
                });
            }
        };
})(jQuery);